/*
	File:	std/mem.hpp
	Date:	2013-06-01
	Author:	Asteroth
*/


#ifndef __ZEN_MEM_HPP__
#define __ZEN_MEM_HPP__

/*

namespace std {

	template <typename valueType, typename memoryAllocator = DefaultAllocator>
	class ArrayAllocator {

	public:

		typedef memoryAllocator<valueType> MemoryAllocator;
		
		static valueType* alloc();
		static void free(valueType* value);

		static valueType* allocArray(unsigned int size0);
		static void freeArray(valueType* value);

		static valueType** allocArray(unsigned int size0, unsigned int size1);
		static void freeArray(valueType** value);

		static valueType*** allocArray(unsigned int size0, unsigned int size1, unsigned int size2);
		static void freeArray(valueType*** value);

		static valueType**** allocArray(unsigned int size0, unsigned int size1, unsigned int size2, unsigned int size3);
		static void freeArray(valueType**** value);

		static valueType***** allocArray(unsigned int size0, unsigned int size1, unsigned int size2, unsigned int size3, unsigned int size4);
		static void freeArray(valueType***** value);

	};

	template <typename valueType>
	inline valueType* SmartAllocator<valueType>::alloc() {
		MemoryAllocator allocator;
		return allocator::alloc();
	}

	template <typename valueType>
	inline void SmartAllocator<valueType>::free(valueType* value) {
		MemoryAllocator allocator;
		return allocator::dealloc(value);
	}
	
	template <typename valueType>
	inline valueType* SmartAllocator<valueType>::allocArray(unsigned int size0) {
		MemoryAllocator allocator;
		return allocator::allocArray(size0);
	}

	template <typename valueType>
	inline void SmartAllocator<valueType>::freeArray(valueType* value) {
		MemoryAllocator allocator;
		return allocator::deallocArray(value);
	}
	
	template <typename valueType>
	inline valueType** SmartAllocator<valueType>::allocArray(unsigned int size0, unsigned int size1) {
		valueType* arr2 = SmartAllocator<valueType>::allocArray(size0 * size1);
		valueType** arr = SmartAllocator<valueType*>::allocArray(size0);
		for (int i = 0; i < size0; i++) arr[i] = &(arr2[i * size1]);
		return arr;
	}

	template <typename valueType>
	inline void SmartAllocator<valueType>::freeArray(valueType** value) {
		if (value != nullptr) {
			SmartAllocator<valueType>::freeArray(value[0]);
			SmartAllocator<valueType*>::freeArray(value);
		}
	}
	
	template <typename valueType>
	inline valueType*** SmartAllocator<valueType>::allocArray(unsigned int size0, unsigned int size1, unsigned int size2) {
		valueType** arr2 = SmartAllocator<valueType>::allocArray(size0 * size1, size2);
		valueType*** arr = SmartAllocator<valueType**>::allocArray(size0);
		for (int i = 0; i < size0; i++) arr[i] = &(arr2[i * size1]);
		return arr;
	}

	template <typename valueType>
	inline void SmartAllocator<valueType>::freeArray(valueType*** value) {
		if (value != nullptr) {
			SmartAllocator<valueType>::freeArray(value[0]);
			SmartAllocator<valueType**>::freeArray(value);
		}
	}

	template <typename valueType>
	inline valueType**** SmartAllocator<valueType>::allocArray(unsigned int size0, unsigned int size1, unsigned int size2, unsigned int size3) {
		valueType*** arr2 = SmartAllocator<valueType>::allocArray(size0 * size1, size2, size3);
		valueType**** arr = SmartAllocator<valueType***>::allocArray(size0);
		for (int i = 0; i < size0; i++) arr[i] = &(arr2[i * size1]);
		return arr;
	}

	template <typename valueType>
	inline void SmartAllocator<valueType>::freeArray(valueType**** value) {
		if (value != nullptr) {
			SmartAllocator<valueType>::freeArray(value[0]);
			SmartAllocator<valueType***>::freeArray(value);
		}
	}

	template <typename valueType>
	inline valueType***** SmartAllocator<valueType>::allocArray(unsigned int size0, unsigned int size1, unsigned int size2, unsigned int size3,  unsigned int size4) {
		valueType**** arr2 = SmartAllocator<valueType>::allocArray(size0 * size1, size2, size3, size4);
		valueType***** arr = SmartAllocator<valueType****>::allocArray(size0);
		for (int i = 0; i < size0; i++) arr[i] = &(arr2[i * size1]);
		return arr;
	}

	template <typename valueType>
	inline void SmartAllocator<valueType>::freeArray(valueType***** value) {
		if (value != nullptr) {
			SmartAllocator<valueType>::freeArray(value[0]);
			SmartAllocator<valueType****>::freeArray(value);
		}
	}


} // namespace std

*/

#endif // __ZEN_MEM_HPP__